package com.tuyrt.firstcode.kotlin.delegate

import kotlin.reflect.KProperty

/**
 * Created by tuyrt7 on 2021/4/9.
 */
class MyClass {
    //调用 p，自动调用 Delegate 类的 getValue()
    var param by Delegate
}

object Delegate {

    var propValue: Any? = null

    operator fun getValue(myClass: MyClass, prop: KProperty<*>): Any? {
        return propValue
    }

    operator fun setValue(myClass: MyClass, prop: KProperty<*>, value: Any?) {
        propValue = value
    }
}